package com.zbkj.service.service.project.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.zbkj.common.model.project.AireqTask;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zbkj.service.dao.project.AireqTaskMapper;
import com.zbkj.service.service.project.AireqTaskService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * ai结算请求任务表 服务实现类
 * </p>
 *
 * @author 
 * @since 2024-09-12
 */
@Service
public class AireqTaskServiceImpl extends ServiceImpl<AireqTaskMapper, AireqTask> implements AireqTaskService {

    @Override
    public void initReqTest(Long projectId, String aireqNo) {
        AireqTask task = new AireqTask();
        task.setProjectId(projectId);
        task.setReqNo(aireqNo);
        this.save(task);
    }

    @Override
    public void updateTaskStatus(Long id, Integer status, String mark) {
        LambdaUpdateWrapper<AireqTask> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(AireqTask::getTaskStatus, status);
        if(StringUtils.isNotBlank(mark)) {
            updateWrapper.set(AireqTask::getMark, mark);
        }
        if(status.intValue() == 0) {
            updateWrapper.setSql(" retry_num = retry_num + 1");
        }
        updateWrapper.eq(AireqTask::getId,id);
        this.update(updateWrapper);
    }
}
